var scrollObj_otherPersonFlowers=null;
$( document ).on( "pageshow", "#otherPersonInfo", function( event ) {
	
	loadOtherInfo(event);
	
	var empId=getParameterByName("empId" , getLocationUrl(event) );
	pageNo="1";
	pageSize="5";
	$("#wrapper_otherPersonFlowers  #pullDown").hide();
	
	scrollObj_otherPersonFlowers=scrollPlugLoadedOfReturn("wrapper_otherPersonFlowers",
			function() {
				setTimeout(function () {
					if(pageNo >= totalPage)
						return;
					pageNo++;
					loadData_otherPersonFlowers(false,empId,scrollObj_otherPersonFlowers);
				}, 1000);	
			},
			function() {
//				setTimeout(function () {
//					pageNo=1;
//					loadData_redFlowerRank(true);
//				}, 1000);
				scrollObj_otherPersonFlowers.refresh();
			});
	loadData_otherPersonFlowers(true,empId,scrollObj_otherPersonFlowers);
});
/**
 * 
 * @param isFresh 是否刷新
 * @param isFresh 是否是分页加载数据
 */
function loadData_otherPersonFlowers(isFresh,empId,scrollObj_otherPersonFlowers){
$.ajax({
	  	url: rootPath+"/review/reviewMeInfos.do",
	  	type: "POST",
	  	dataType: "text",
		data: "access_token="+access_token+"&pageNo="+pageNo+"&pageSize="+pageSize+"&empId="+empId,
	  	success: function( response ) {
	  		var data=$.parseJSON(response);
			if(data.state=="200"){
				totalPage=data.data.totalPage;
		  		var totalRow=data.data.totalRow;
		  		var arr=data.data.rows;
				var content = "";
				for (var i=0;i<arr.length;i++){
					content+="<li data-icon=\"false\">"+
								  "<a href=\"#\">"+
									" <p >" +
									 	"<span style=\"font-size:15px;\">"+
											"<b>"+arr[i].criticsName+"</b>送给" + arr[i].byCriticsName + "一朵<img src=\"../../images/weixin/flower/flower_bloom.gif\" width=\"25\" height=\"25\"/>" +
										"</span>"+
										"<strong class=\"ui-li-aside_fresh_new\">"+arr[i].create_timeStr+"</strong>"+
									"</p>" +
									"<p>"+replaceContent(arr[i].reviewContent)+"</p>"+
								  "</a>"+
								"</li>";
				}
				if(arr.length<pageSize){
					$("#wrapper_otherPersonFlowers  #pullUp").hide();
				}else{
					$("#wrapper_otherPersonFlowers  #pullUp").show();
				}
				if(isFresh && $("#thelist_otherPersonFlowers").html()!=""){
					$("#thelist_otherPersonFlowers").html("");
				}
				$("#thelist_otherPersonFlowers").append(content).listview('refresh');
				
				scrollObj_otherPersonFlowers.refresh();
				
			}else{
				alert_wx('fail',data.msg);
			}
	  	}
	});
}
function loadOtherInfo(event) {
	access_token=getParameterByName("access_token",getLocationUrl(event));//getQueryString("access_token");
	var empId=getParameterByName("empId",getLocationUrl(event));
	var url=rootPath+"/user/personInfo.do";
	$.ajax({
	  	url: url,
	  	type: "GET",
	  	dataType: "text",
		data: "access_token="+access_token+"&empId="+empId,
	  	success: function( response ) {
	  		var data=$.parseJSON(response);
	  		
			if(data.state=="200"){
		  		var user=data.data;
		  		var userTelephone=user.telephone==undefined||user.telephone==null? "":user.telephone;
		  		var userWorkEmail=user.work_email==undefined||user.work_email==null? "":user.work_email;
		  		var userDeptName=user.deptName==undefined||user.deptName==null? "":user.deptName;
		  		$("#otherPerson_home_page").html(user.empName+"的主页");
		  		$("#userName").text(user.empName);
		  		$("#userGrade").text(user.integralGrade);
		  		$("#userIntegralNum").text(user.integralNum);
		  		$("#userFlowerNum").text(parseInt(user.redFlowerNum+user.fdFlowerNum));
		  		$("#userDeptName").text(userDeptName);
		  		$("#userTelephone").val(userTelephone);
		  		$("#userWorkEmail").text(userWorkEmail);
		  		
		  		var userHeadPic=user.headImageUrl==undefined||user.headImageUrl==null? rootPath+defaultHeadPic :user.headImageUrl;
		  		
		  		$("#userHead").attr("src",userHeadPic);
		  		$("#userIntegralPic_myInfo").attr("src",rootPath+user.inteGraPic);
		  		var flowerUrl="";
		  		if(user.redflowerState=="死掉"){
		  			flowerUrl=flower_die;
		  		}else if(user.redflowerState=="枯萎"){
		  			flowerUrl=flower_droop;
		  		}else if(user.redflowerState=="盛开"){
		  			flowerUrl=flower_bloom;
		  		}
		  		$("#userFlowerStatePic").attr("src",rootPath+flowerUrl);
			}else{
				alert_wx("fail",data.msg);
			}
	  	}
	});
	//送花
	$("#btn_sendFlower").on("click",function (){
		goTo(rootPath+"/jsp/weixin/sendReview.jsp?empId="+empId+"&access_token="+access_token,false);
	});
}